package Cordiali_Es2;

import java.util.HashMap;

import arjuna.JavaSim.Simulation.Scheduler;

public class User {
	
	public double arrivalTime, currentJobTime;
	private HashMap<Server, ServerInfo> servers = new HashMap<Server, ServerInfo>();
		
	public User() {
		arrivalTime = Scheduler.CurrentTime();
	}

	double currentArrivalTime;
	public void markArrived(Server s)
	{		
		currentArrivalTime = Server.CurrentTime();
	}
	public void markStartServed(Server s)
	{
		ServerInfo si = getServerInfo(s);
		si.queueTime+=Server.CurrentTime()-currentArrivalTime;		
	}
	public void markFinishServed(Server s)
	{
		ServerInfo si = getServerInfo(s);
		si.totalTime+=Server.CurrentTime()-currentArrivalTime;
		si.visitCount++;
	}
	
	public double getResponceTime(Server s)
	{
		ServerInfo si = getServerInfo(s);
		if(si.visitCount==0)
			return 0;
		return si.totalTime/si.visitCount;
	}
	
	public double getQueueTime(Server s)
	{
		ServerInfo si = getServerInfo(s);
		return si.queueTime;
	}
	
	public int getServerUsage(Server s)
	{
		ServerInfo si = getServerInfo(s);
		return (int)si.visitCount;
	}
	
	public double getVisitCount(Server s)
	{
		ServerInfo si = getServerInfo(s);
		return si.visitCount;
	}
	
	
	public class ServerInfo
	{
		public double queueTime, totalTime, visitCount;
	}
	
	private ServerInfo getServerInfo(Server s)
	{
		if(!servers.containsKey(s))
			servers.put(s,new ServerInfo());
		return servers.get(s);
	}
	
	
	
	
//	public void finished() {
//		ResponseTime = Scheduler.CurrentTime() - arrivalTime;
//		ECommerceShop.TotalResponseTime += ResponseTime;
//	}
}
